home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 223_01 / uw.c < prev    next >
Text File  |  1980-01-01  |  1KB  |  49 lines

  1. /*    
  2. ** uw.c        File Copy & UW(Bin) Program    by F.A.Scacchitti  7/17/84
  3. **
  4. **        Written in Small-C Version 2.09 or later
  5. **
  6. **        Copies file from file to file
  7. **        Un-wordstars as it goes (resets bit 7 of all bytes)
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. #define BUFSIZE 0X4000  /* 16K */
  13.  
  14. FILE fdin, fdout;    /* file  i/o channel pointers */
  15. int i, j, count;
  16. char *inbuf;
  17.  
  18. main(argc,argv) int argc; char *argv[]; {
  19.  
  20.    i = 0;
  21.    inbuf = malloc(BUFSIZE);
  22.  
  23.    if(argc != 3) {
  24.     puts("\nuw usage: uw <source file> <new file> <CR>\n");
  25.     exit();
  26.    }
  27.    if((fdin = fopen(argv[1],"r")) == NULL) {
  28.       puts("\nUnable to open input file.\n");
  29.       exit();
  30.    }
  31.    if((fdout = fopen(argv[2],"w")) == NULL) {
  32.       puts("\nUnable to create output file.\n");
  33.       exit();
  34.    }
  35.  
  36.    while((count = read(fdin,inbuf,BUFSIZE)) == BUFSIZE) {
  37.       for(j = 0; j < BUFSIZE; j++) inbuf[j] = inbuf[j] & 127;
  38.       write(fdout,inbuf,count);
  39.       i += count;
  40.    }
  41.    i += count;
  42.       for(j = 0; j < count % BUFSIZE; j++) inbuf[j] = inbuf[j] & 127;
  43.    write(fdout,inbuf,count);
  44.  
  45.    fclose(fdin);
  46.    fclose(fdout);
  47. }
  48.  
  49.